package com.sinoglobal.ningxia.adapter;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.PlayBillBean;

/**
 * @author qiwx
 * @createdate 2014-6-24 上午10:53:03
 * @Description: 节目单
 */
public class PlayBillAdapter extends BaseAdapter {

	List<PlayBillBean> data;
	private Context context;
	LayoutInflater mInflater;
	boolean isDate;// true 显示日期，false 不显示日期

	public PlayBillAdapter(Context context, List<PlayBillBean> data,
			boolean flag) {
		if (context == null)
			return;
		this.context = context;
		this.data = data;
		isDate = flag;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		if (data != null)
			return data.size();
		else
			return 0;
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewholder;
		if (convertView == null) {
			viewholder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.playbill_listview_item,
					null);
			if (isDate)
				viewholder.setDate((TextView) convertView
						.findViewById(R.id.billDate));
			viewholder.setTime((TextView) convertView
					.findViewById(R.id.billTime));
			viewholder.setName((TextView) convertView
					.findViewById(R.id.billName));
			viewholder.setCircle((ImageView) convertView
					.findViewById(R.id.billCircle));
			convertView.setTag(viewholder);
		} else {
			viewholder = (ViewHolder) convertView.getTag();
		}
		PlayBillBean bean = data.get(position);
		if (isDate) {
			viewholder.getDate().setText(bean.getDate());
			viewholder.getDate().setVisibility(View.VISIBLE);
		}

		viewholder.getTime().setText(bean.getTime());
		viewholder.getName().setText(bean.getJiemuname());
		int type = 0;// 类型 0代表已经播出，1代表正在播出，2代表未播出
		try {
			type = Integer.valueOf(bean.getType());
		} catch (Exception e) {
			e.printStackTrace();

		}
		switch (type) {
		case 0:
			viewholder.getCircle().setImageDrawable(
					context.getResources().getDrawable(
							R.drawable.bill_circle_gray));
			break;
		case 1:
			viewholder.getCircle().setImageDrawable(
					context.getResources().getDrawable(
							R.drawable.bill_circle_yellow));
			break;
		case 2:
			viewholder.getCircle().setImageDrawable(
					context.getResources().getDrawable(
							R.drawable.bill_circle_red));
			break;
		}

		return convertView;
	}

	class ViewHolder {
		TextView date;
		TextView time;
		TextView Name;
		ImageView circle;

		public TextView getDate() {
			return date;
		}

		public void setDate(TextView date) {
			this.date = date;
		}

		public TextView getTime() {
			return time;
		}

		public void setTime(TextView time) {
			this.time = time;
		}

		public TextView getName() {
			return Name;
		}

		public void setName(TextView name) {
			Name = name;
		}

		public ImageView getCircle() {
			return circle;
		}

		public void setCircle(ImageView circle) {
			this.circle = circle;
		}

	}

}
